<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">-- Copyright 2016 TensorFlow authors.</span><span>
</span><span id="line-2"></span><span class="hs-comment">--</span><span>
</span><span id="line-3"></span><span class="hs-comment">-- Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span><span>
</span><span id="line-4"></span><span class="hs-comment">-- you may not use this file except in compliance with the License.</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- You may obtain a copy of the License at</span><span>
</span><span id="line-6"></span><span class="hs-comment">--</span><span>
</span><span id="line-7"></span><span class="hs-comment">--     http://www.apache.org/licenses/LICENSE-2.0</span><span>
</span><span id="line-8"></span><span class="hs-comment">--</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Unless required by applicable law or agreed to in writing, software</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- See the License for the specific language governing permissions and</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- limitations under the License.</span><span>
</span><span id="line-14"></span><span>
</span><span id="line-15"></span><span class="hs-pragma">{-# LANGUAGE OverloadedStrings #-}</span><span>
</span><span id="line-16"></span><span>
</span><span id="line-17"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">TensorFlow.Test</span><span>
</span><span id="line-18"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="TensorFlow.Test.html#assertAllClose"><span class="hs-identifier">assertAllClose</span></a></span><span>
</span><span id="line-19"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-20"></span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Vector</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">V</span></span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Test.HUnit</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-operator">(@?)</span></span><span class="hs-special">)</span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Test.HUnit.Lang</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Assertion</span></span><span class="hs-special">)</span><span>
</span><span id="line-24"></span><span class="hs-comment">-- | Compares that the vectors are element-by-element equal within the given</span><span>
</span><span id="line-25"></span><span class="hs-comment">-- tolerance. Raises an assertion and prints some information if not.</span><span>
</span><span id="line-26"></span><span class="annot"><a href="TensorFlow.Test.html#assertAllClose"><span class="hs-identifier hs-type">assertAllClose</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">V.Vector</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">V.Vector</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Assertion</span></span><span>
</span><span id="line-27"></span><span id="assertAllClose"><span class="annot"><span class="annottext">assertAllClose :: Vector Float -&gt; Vector Float -&gt; Assertion
</span><a href="TensorFlow.Test.html#assertAllClose"><span class="hs-identifier hs-var hs-var">assertAllClose</span></a></span></span><span> </span><span id="local-6989586621679033134"><span class="annot"><span class="annottext">xs :: Vector Float
</span><a href="#local-6989586621679033134"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span id="local-6989586621679033133"><span class="annot"><span class="annottext">ys :: Vector Float
</span><a href="#local-6989586621679033133"><span class="hs-identifier hs-var">ys</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Float -&gt; Bool) -&gt; Vector Float -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><span class="hs-identifier hs-var">all</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Float -&gt; Float -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;=</span></span><span> </span><span class="annot"><span class="annottext">Float
</span><a href="#local-6989586621679033130"><span class="hs-identifier hs-var">tol</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Float -&gt; Float -&gt; Float)
-&gt; Vector Float -&gt; Vector Float -&gt; Vector Float
forall a b c. (a -&gt; b -&gt; c) -&gt; Vector a -&gt; Vector b -&gt; Vector c
</span><span class="hs-identifier hs-var">V.zipWith</span></span><span> </span><span class="annot"><span class="annottext">Float -&gt; Float -&gt; Float
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="#local-6989586621679033128"><span class="hs-identifier hs-var">absDiff</span></a></span><span> </span><span class="annot"><span class="annottext">Vector Float
</span><a href="#local-6989586621679033134"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">Vector Float
</span><a href="#local-6989586621679033133"><span class="hs-identifier hs-var">ys</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; String -&gt; Assertion
forall t.
(HasCallStack, AssertionPredicable t) =&gt;
t -&gt; String -&gt; Assertion
</span><span class="hs-operator hs-var">@?</span></span><span>
</span><span id="line-28"></span><span>    </span><span class="annot"><span class="hs-string">&quot;Difference &gt; tolerance: \nxs: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="annottext">Vector Float -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><span class="hs-identifier hs-var">show</span></span><span> </span><span class="annot"><span class="annottext">Vector Float
</span><a href="#local-6989586621679033134"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="hs-string">&quot;\nys: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="annottext">Vector Float -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><span class="hs-identifier hs-var">show</span></span><span> </span><span class="annot"><span class="annottext">Vector Float
</span><a href="#local-6989586621679033133"><span class="hs-identifier hs-var">ys</span></a></span><span>
</span><span id="line-29"></span><span>        </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="hs-string">&quot;\ntolerance: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="annottext">Float -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><span class="hs-identifier hs-var">show</span></span><span> </span><span class="annot"><span class="annottext">Float
</span><a href="#local-6989586621679033130"><span class="hs-identifier hs-var">tol</span></a></span><span>
</span><span id="line-30"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-31"></span><span>      </span><span id="local-6989586621679033128"><span class="annot"><span class="annottext">absDiff :: a -&gt; a -&gt; a
</span><a href="#local-6989586621679033128"><span class="hs-identifier hs-var hs-var">absDiff</span></a></span></span><span> </span><span id="local-6989586621679033126"><span class="annot"><span class="annottext">x :: a
</span><a href="#local-6989586621679033126"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679033125"><span class="annot"><span class="annottext">y :: a
</span><a href="#local-6989586621679033125"><span class="hs-identifier hs-var">y</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; a
forall a. Num a =&gt; a -&gt; a
</span><span class="hs-identifier hs-var">abs</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679033126"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-glyph hs-var">-</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679033125"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-32"></span><span>      </span><span id="local-6989586621679033130"><span class="annot"><span class="annottext">tol :: Float
</span><a href="#local-6989586621679033130"><span class="hs-identifier hs-var hs-var">tol</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="hs-number">0.001</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span>
</span><span id="line-33"></span></pre></body></html>